package com.item.audrey_hepburn.factory;/*/**

 _______  _______________   _________________________  __________ ____ ___  ________ 
 \      \ \_   _____/\   \ /   /\_   _____/\______   \ \______   \    |   \/  _____/ 
 /   |   \ |    __)_  \   Y   /  |    __)_  |       _/  |    |  _/    |   /   \  ___ 
/    |    \|        \  \     /   |        \ |    |   \  |    |   \    |  /\    \_\  \
\____|__  /_______  /   \___/   /_______  / |____|_  /  |______  /______/  \______  /
        \/        \/                    \/         \/          \/                 \/ 
 
 * @Auther: WD
 * @Date: 19-5-8 21:25
 * @Description: 火车票
 */

import com.alibaba.fastjson.JSONArray;
import com.item.audrey_hepburn.entity.db2.Ticket;

import java.util.ArrayList;
import java.util.List;

public class TrainTickets implements TicketFactory {

    @Override
    public List<Ticket> findByTypeInfo(JSONArray jsonArray) {
        List<Ticket>tickets=new ArrayList<>();
        Ticket ticket =null;
        for(int i=0;i<jsonArray.size();i++) {
            String result = jsonArray.get(i).toString();
            //System.out.println(result);

            String TrainNumber = result.split("\\|")[3];
            String[] datas = result.split("\\|");
            if (TrainNumber.split("")[0].equals("K")) {
                String[] TicketType = result
                        .split("\\|\\|\\|\\|")[1]
                        .replaceAll("\\|\\|\\|", "\\|")
                        .replaceAll("\\|\\|", "\\|")
                        .split("\\|");


                ticket = new Ticket
                        .Builder()
                        .setTRAINNUMBER(TrainNumber)
                        .setTICKETTYPE("火车票")
                        .setSTART(datas[6])
                        .setEND(datas[7])
                        .setSTARTTIME(datas[8])
                        .setENDTIME(datas[9])
                        .setUSETIME(datas[10])
                        .setHIGHGRADESOFTBERTH(null)
                        .setORDINARYSOFTSLEEPER(TicketType[0])
                        .setHARDSLEEPER(TicketType[2])
                        .setSOFTSEATS(null)
                        .setHARDSEAT(TicketType[3])
                        .setNOSEAT(TicketType[1])
                        .setBUSINESSBLOCK(null)
                        .setFIRSTCLASSSEAT(null)
                        .setSECONDCLASSSEAT(null)
                        .builder()
                ;
                tickets.add(ticket);
            }
        }
        return tickets;
    }
}
